package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmMaterialDto;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.service.MaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @projectName: heima-leadnews
 * @package: com.heima.wemedia.controller.v1
 * @className: PicktureController
 * @author: 躺着认真玩
 * @description: 素材管理
 * @date: 2025/5/19 4:45
 * @version: 1.0
 */
@RestController
@RequestMapping("/api/v1/material")
public class MaterialController {
    @Autowired
    private MaterialService materialService;

    @PostMapping("/upload_picture")
    public ResponseResult uploadPickture(MultipartFile multipartFile){
        return materialService.upload(multipartFile);
    }

    @PostMapping("/list")
    public PageResponseResult list(@RequestBody WmMaterialDto wmMaterialDto){
        return materialService.list(wmMaterialDto);
    }

    /**
     * @param id
     * 根据id删除素材
     */
    @GetMapping("/del_picture/{id}")
    public void delete(@PathVariable Integer id){
        materialService.removeById(id);
    }

    @GetMapping("/collect/{id}")
    public void collect(@PathVariable Integer id){
        WmMaterial po = new WmMaterial();
        po.setId(id);
        po.setIsCollection((short)1);
        materialService.updateById(po);
    }
}
